package com.wjh.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.wjh.interceptor.LoginInterceptor;
import com.wjh.util.RedisUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * Web配置类
 * 
 * @author wenjianhai
 * @date 2023/6/22
 * @since JDK 17
 */
@Slf4j
@Configuration
public class WebConfig implements WebMvcConfigurer {

	@Autowired
	private RedisUtils redisUtils;

	/**
	 * 配置拦截器
	 * 
	 * @param registry 相当于拦截器的注册中心
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		log.info("配置拦截器-开始.");
		// 对所有访问路径，都通过LoginInterceptor类型的拦截器进行拦截
		registry.addInterceptor(new LoginInterceptor(redisUtils)).addPathPatterns("/**")
				// 放行登录页，登陆操作，静态资源、swagger、springdoc
				.excludePathPatterns("/login/web", "/goods/api/**", "/doc.html", "/doc.html#/home", "/swagger-ui/**",
						"/webjars/**", "/index.html", "/css/**", "/images/**", "/js/**", "/fonts/**", "/*.ico",
						"/v3/**");
	}
}
